package com.gupaoedu.pattern.jdbc;

import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * 2019/9/28
 * created by chenpp
 */
public class StudentDao extends JdbcTemplate {
    public StudentDao(DataSource dataSource) {
        super(dataSource);
    }
    public List<?> selectAll(){
        String sql = "select * from student";
        return super.executeQuery(sql, new RowMapper<Student>() {
            public Student mapRow(ResultSet rs, int rowNum) throws Exception {
                Student student = new Student();
                int age =  rs.getInt("age");
                String name  = rs.getString("name");
                String no = rs.getString("no");
                student.setAge(age);
                student.setName(name);
                student.setNo(no);
                return student;
            }
        }, null);
    }
}
